const UserLike = require('../model/UserLikes_model')

class UserLikeService {

    //喜欢
    async keenMusic(data) {
        try {
            const res = UserLike.create(data)
            return { res }
        } catch (error) {
            console.log(error);

        }

    }
    //不喜欢
    async cancalUserMusic(data) {
        try {
            const { id, user_id } = data
            const result = await UserLike.destroy({
                where: {
                    id,
                    user_id
                }
            })
            return result
        } catch (error) {
            console.log(error);
        }
    }

    async findMusic(user_id) {

        const res = await UserLike.findAll({
            where: {
                user_id
            }
        })
        return res
    }

    async findMyfavoriteMusic(params) {
        try {
            const { user_id, pageNo, pageSize } = params
            console.log(user_id, pageNo, pageSize);

            const limit = pageSize * 1
            const offset = (pageNo * 1 - 1) * pageSize
            const { count, rows } = await UserLike.findAndCountAll({
                where: { user_id },
                order: [['createdAt', 'DESC']],
                attributes: ['id', 'Songname', 'imgUrl', 'album', 'albumid', 'artist', 'artistid', 'isFavorite', 'dt'],
                offset, limit
            })
            return { count, songlist: rows }
        } catch (error) {
            console.log(error);

        }

    }
}

module.exports = new UserLikeService()